package com.jl.jlapp.mvp.fragment;

import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter.OnItemChildClickListener;
import com.jl.jlapp.R;
import com.jl.jlapp.adapter.GeneralInvoiceListAdapter;
import com.jl.jlapp.eneity.CommitVatInvoiceAptitudeToCheckModel;
import com.jl.jlapp.eneity.GeneralInvoiceModel;
import com.jl.jlapp.eneity.GeneralInvoiceModel.ResultDataBean;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.eneity.VatInvoiceAptitudeByUserIdModel;
import com.jl.jlapp.mvp.activity.AddGeneralInvoiceActivity;
import com.jl.jlapp.mvp.activity.AddVatInvoiceActivity;
import com.jl.jlapp.mvp.activity.LoginActivity;
import com.jl.jlapp.mvp.activity.PhotoViewActivity;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.CommonObserver;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.nets.Transformer;
import com.jl.jlapp.popu.ClearHistorySearhPopu;
import com.jl.jlapp.utils.Tools;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

import java.util.List;

public class InvoiceFragment extends LazyLoadFragment implements OnClickListener {
    private static final String EXTRA_TYPE = "extra_type";
    public static final int TYPE_UNITINVOICE = 2;
    public static final int TYPE_VATINVOICE = 1;
    @BindView(R.id.add_general_invoice_linear)
    LinearLayout addGeneralInvoiceLinear;
    @BindView(R.id.add_text)
    TextView addText;
    @BindView(R.id.bankAccount)
    TextView bankAccount;
    ClearHistorySearhPopu clearHistorySearhPopu = null;
    @BindView(R.id.depositBank)
    TextView depositBank;
    GeneralInvoiceListAdapter generalInvoiceListAdapter;
    List<GeneralInvoiceModel.ResultDataBean> generalInvoiceResultDataBeans = null;
    @BindView(R.id.lrv_list)
    RecyclerView lrvList;
    @BindView(R.id.no_invoice_show)
    RelativeLayout noInvoiceShow;
    String picUrl;
    @BindView(R.id.registeredAddress)
    TextView registeredAddress;
    @BindView(R.id.registeredTel)
    TextView registeredTel;
    @BindView(R.id.taxpayerIdentificationNumber)
    TextView taxpayerIdentificationNumber;
    @BindView(R.id.tv_delete)
    TextView tvDelete;
    @BindView(R.id.state)
    TextView tvState;
    @BindView(R.id.tv_update)
    TextView tvUpdate;
    int type = 1;
    Unbinder unbinder;
    @BindView(R.id.unitName)
    TextView unitName;
    int userId = 0;
    @BindView(R.id.vat_invoice_content)
    LinearLayout vatInvoiceContent;
    int vatInvoiceId = 0;
    @BindView(R.id.vat_pic)
    ImageView vatPic;
    VatInvoiceAptitudeByUserIdModel.ResultDataBean vatResultDataBean = null;

    private void initDatas(int paramInt) {
        switch (paramInt) {
            case 1:
                this.addText.setText("添加增票资质");
                if (this.vatResultDataBean == null) {
                    this.lrvList.setVisibility(View.GONE);
                    this.addGeneralInvoiceLinear.setVisibility(View.GONE);
                    this.noInvoiceShow.setVisibility(View.VISIBLE);
                    this.vatInvoiceContent.setVisibility(View.GONE);
                    this.addText.setOnClickListener(this);
                    return;
                }
                this.lrvList.setVisibility(View.GONE);
                this.addGeneralInvoiceLinear.setVisibility(View.GONE);
                this.noInvoiceShow.setVisibility(View.GONE);
                this.vatInvoiceContent.setVisibility(View.VISIBLE);
                this.tvUpdate.setOnClickListener(this);
                this.tvDelete.setOnClickListener(this);
                this.vatPic.setOnClickListener(this);

                this.vatInvoiceId = this.vatResultDataBean.getId();
                this.unitName.setText(this.vatResultDataBean.getUnitName());
                this.taxpayerIdentificationNumber.setText(this.vatResultDataBean.getTaxpayerIdentificationNumber());
                this.registeredAddress.setText(this.vatResultDataBean.getRegisteredAddress());
                this.registeredTel.setText(this.vatResultDataBean.getRegisteredTel());
                this.depositBank.setText(this.vatResultDataBean.getDepositBank());
                this.bankAccount.setText(this.vatResultDataBean.getBankAccount());
                this.picUrl = this.vatResultDataBean.getBusinessLicenseUrl();
                if ((this.picUrl != null) && (this.picUrl != "")) {
                    break;
                }
                Glide.with(getActivity()).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_noimg_m).error(R.drawable.img_noimg_m)).load(Integer.valueOf(R.drawable.img_noimg_m)).into(this.vatPic);
                this.tvState.setText("增票资质已提交审核");
                this.tvState.setBackgroundResource(R.color.state_wait_check);
                Drawable localDrawable = getResources().getDrawable(R.drawable.checkmark_going);
                this.tvState.setCompoundDrawablesWithIntrinsicBounds(localDrawable, null, null, null);
                this.tvState.setText("您填写的增票资质未通过审核，请重新填写");
                this.tvState.setBackgroundResource(R.color.state_dis_pass);
                localDrawable = getResources().getDrawable(R.drawable.checkmark_wrong);
                this.tvState.setCompoundDrawablesWithIntrinsicBounds(localDrawable, null, null, null);
                this.tvState.setText("已通过审核");
                this.tvState.setBackgroundResource(R.color.state_pass);
                localDrawable = getResources().getDrawable(R.drawable.checkmark_green);
                this.tvState.setCompoundDrawablesWithIntrinsicBounds(localDrawable, null, null, null);

                Glide.with(getActivity()).asBitmap().apply(new RequestOptions().placeholder(R.drawable.img_lose_m).error(R.drawable.img_lose_m)).load("http://117.158.178.202:8001/JLMIS/" + this.picUrl).into(this.vatPic);
                break;
        }
        this.addGeneralInvoiceLinear.setOnClickListener(this);
        getInvoiceUnitByUserId(this.userId);
    }

    public static InvoiceFragment newInstance(int paramInt1, int paramInt2) {
        InvoiceFragment localInvoiceFragment = new InvoiceFragment();
        Bundle localBundle = new Bundle();
        localBundle.putInt("extra_type", paramInt1);
        localBundle.putInt("userId", paramInt2);
        localInvoiceFragment.setArguments(localBundle);
        return localInvoiceFragment;
    }

    private void setGeneralInvoiceListAdapter() {
        this.lrvList.setLayoutManager(new LinearLayoutManager(getContext()));
        this.generalInvoiceListAdapter = new GeneralInvoiceListAdapter(R.layout.general_invoice_list_item_layout, this.generalInvoiceResultDataBeans);
        this.lrvList.setAdapter(this.generalInvoiceListAdapter);
        this.generalInvoiceListAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            public void onItemChildClick(BaseQuickAdapter paramAnonymousBaseQuickAdapter, View paramAnonymousView, final int paramAnonymousInt) {
                switch (paramAnonymousView.getId()) {
                    case R.id.general_invoice_edit_linear:
                        Intent intent = new Intent(InvoiceFragment.this.getContext(), AddGeneralInvoiceActivity.class);
                        intent.putExtra("whichButton", 1);
                        intent.putExtra("unitId", ((GeneralInvoiceModel.ResultDataBean) InvoiceFragment.this.generalInvoiceResultDataBeans.get(paramAnonymousInt)).getId());
                        intent.putExtra("unitName", ((GeneralInvoiceModel.ResultDataBean) InvoiceFragment.this.generalInvoiceResultDataBeans.get(paramAnonymousInt)).getUnitName());
                        intent.putExtra("taxpayerIdentificationNumber", ((GeneralInvoiceModel.ResultDataBean) InvoiceFragment.this.generalInvoiceResultDataBeans.get(paramAnonymousInt)).getTaxpayerIdentificationNumber());
                        InvoiceFragment.this.startActivity(intent);
                        break;
                }
                InvoiceFragment.this.clearHistorySearhPopu = new ClearHistorySearhPopu(InvoiceFragment.this.getContext(), new OnClickListener() {
                    public void onClick(View paramAnonymous2View) {
                        InvoiceFragment.this.clearHistorySearhPopu.dismiss();
                        InvoiceFragment.this.deleteInvoiceUnitById(((GeneralInvoiceModel.ResultDataBean) InvoiceFragment.this.generalInvoiceResultDataBeans.get(paramAnonymousInt)).getId(), InvoiceFragment.this.userId);
                    }
                }, Integer.valueOf(8));
                InvoiceFragment.this.clearHistorySearhPopu.showAtLocation(InvoiceFragment.this.getActivity().findViewById(R.id.invoice_page), 17, 0, 0);
            }
        });
    }

    public void deleteInvoiceUnitById(int paramInt1, int paramInt2) {
        Net.get().deleteInvoiceUnitById(paramInt1, paramInt2)
                .compose(Transformer.<PostModel>switchSchedulers())
                .subscribe(new CommonObserver<PostModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(PostModel postModel) {

                    }
                });
    }

    public void deleteVatInvoiceAptitudeById(int paramInt1, int paramInt2) {
        Net.get().deleteVatInvoiceAptitudeById(paramInt1, paramInt2)
                .compose(Transformer.<CommitVatInvoiceAptitudeToCheckModel>switchSchedulers())
                .subscribe(new CommonObserver<CommitVatInvoiceAptitudeToCheckModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(CommitVatInvoiceAptitudeToCheckModel commitVatInvoiceAptitudeToCheckModel) {

                    }
                });
    }

    public void getInvoiceUnitByUserId(int paramInt) {
        Net.get().getInvoiceUnitByUserId(paramInt)
                .compose(Transformer.<GeneralInvoiceModel>switchSchedulers())
                .subscribe(new CommonObserver<GeneralInvoiceModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(GeneralInvoiceModel generalInvoiceModel) {

                    }
                });
    }

    public void getVatInvoiceAptitudeByUserId(int paramInt) {
        Net.get().getVatInvoiceAptitudeByUserId(paramInt)
                .compose(Transformer.<VatInvoiceAptitudeByUserIdModel>switchSchedulers())
                .subscribe(new CommonObserver<VatInvoiceAptitudeByUserIdModel>() {
                    @Override
                    protected void onError(String errorMsg) {

                    }

                    @Override
                    protected void onSuccess(VatInvoiceAptitudeByUserIdModel vatInvoiceAptitudeByUserIdModel) {

                    }
                });
    }

    public int initLayout() {
        return R.layout.fragment_invoice;
    }

    public void initViews(View paramView) {
        Bundle localBundle = getArguments();
        if ((localBundle == null) || (!localBundle.containsKey("extra_type"))) {
            throw new IllegalArgumentException("NoticeListFragment must be created by type args");
        }
        this.type = localBundle.getInt("extra_type", 1);
        this.userId = localBundle.getInt("userId", 0);
        this.unbinder = ButterKnife.bind(this, paramView);
    }

    public void loadData() {
        if (this.userId > 0) {
            getVatInvoiceAptitudeByUserId(this.userId);
            return;
        }
        Toast.makeText(getContext(), "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
        startActivity(new Intent(getContext(), LoginActivity.class));
    }

    public void onClick(View paramView) {
        Intent intent;
        switch (paramView.getId()) {
            case R.id.add_text:
                if (this.type == 1) {
                    Tools.addActivity(getActivity());
                    intent = new Intent(getActivity(), AddVatInvoiceActivity.class);
                    intent.putExtra("isUpdate", 0);
                    startActivity(intent);
                }
                if (this.type == 2) {
                    intent = new Intent(getActivity(), AddGeneralInvoiceActivity.class);
                    intent.putExtra("whichButton", 0);
                    startActivity(intent);
                }
                break;
            case R.id.add_general_invoice_linear:
                intent = new Intent(getActivity(), AddGeneralInvoiceActivity.class);
                intent.putExtra("whichButton", 0);
                startActivity(intent);
                break;
            case R.id.tv_update:
                Tools.addActivity(getActivity());
                intent = new Intent(getActivity(), AddVatInvoiceActivity.class);
                intent.putExtra("isUpdate", 1);
                String str1 = this.unitName.getText().toString().trim();
                String str2 = this.taxpayerIdentificationNumber.getText().toString().trim();
                String str3 = this.registeredAddress.getText().toString().toString().trim();
                String str4 = this.registeredTel.getText().toString().trim();
                String str5 = this.depositBank.getText().toString().trim();
                String str6 = this.bankAccount.getText().toString().toString().trim();
                intent.putExtra("id", this.vatInvoiceId);
                intent.putExtra("unitName", str1);
                intent.putExtra("taxpayerIdentificationNumber", str2);
                intent.putExtra("registeredAddress", str3);
                intent.putExtra("registeredTel", str4);
                intent.putExtra("depositBank", str5);
                intent.putExtra("bankAccount", str6);
                startActivity(intent);
                break;
            case R.id.tv_delete:
                this.clearHistorySearhPopu = new ClearHistorySearhPopu(getContext(), new OnClickListener() {
                    public void onClick(View paramAnonymousView) {
                        InvoiceFragment.this.clearHistorySearhPopu.dismiss();
                        InvoiceFragment.this.deleteVatInvoiceAptitudeById(InvoiceFragment.this.vatInvoiceId, InvoiceFragment.this.userId);
                    }
                }, Integer.valueOf(10));
                this.clearHistorySearhPopu.showAtLocation(getActivity().findViewById(R.id.invoice_page), 17, 0, 0);
                break;
        }
        intent = new Intent(getActivity(), PhotoViewActivity.class);
        intent.putExtra("picUrl", this.picUrl);
        startActivity(intent);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/fragment/InvoiceFragment.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */